import Home from './views/Home.vue'
const routes = [
  {
    path: '/index',
    name: '首页',
    icon:"iconfont icon-home",
    component: Home
  },
  {
    path: '/site',
    name: '站点管理',
    icon:"iconfont icon-fileset",
    subs: [
      {
        path: '/files',
        name: '文件管理',
        component: () => import( '@/components/site/files.vue')
      },
      {
        path: '/images',
        name: '图片管理',
        subs: [
          {
            path: '/labels',
            name: '图片标签',
            component: () => import( '@/components/site/image/labels.vue')
          },
          {
            path: '/list',
            name: '图片列表',
            component: () => import( '@/components/site/image/images.vue')
          }
        ]
      }
    ]
  },
  {
    path: '/sliders',
    name: '滚动广告',
    icon:"iconfont icon-fileset",
    component: () => import( '@/components/game/sliders.vue')
  },
  {
    path: '/advertisements',
    name: '列表广告',
    icon:"iconfont icon-fileset",
    component: () => import( '@/components/game/advertisements.vue')
  },
];

function initMenus(routes, parentPath) {
  let menus = [];
  for(let route of routes) {
    let path = parentPath? parentPath + route.path: route.path;
    let menu = {
      index: path,
      icon: route.icon?route.icon:"",
      name: route.name
    };
    if(route.subs && route.subs.length >0) {
      menu.subs = initMenus(route.subs, path)
    }
    menus.push(menu);
  }
  return menus;
}

function initRoutes(routes, parentPath) {
  let rs = [];
  for(let route of routes) {
    let path = parentPath? parentPath + route.path: route.path;
    if(route.subs && route.subs.length >0) {
      let subs = initRoutes(route.subs, path);
      for(let sub of subs) {
        rs.push(sub)
      }
    } else {
      let r = {
        path: path,
        name: route.name,
        component: route.component
      };
      rs.push(r)
    }
  }
  return rs;
}

export default {
  routes() {
    return initRoutes(routes, null)
  },
  menus() {
    return initMenus(routes, null)
  }
}
